﻿<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <label for="weight">Weight in kilos:</label>
    <input id="weight" type="text" data-bind="value: weight" /><br />
    <label for="height">Height in meters:</label>
    <input id="height" type="text" data-bind="value: height" />
    <p>
        Body mass index:<span data-bind="text: bmi"></span>
    </p>
    <script type="text/javascript" src="../knockout-3.0.0.js"></script>
    <script>
        function ViewModel() {
            var self = this;
            self.weight = ko.observable();
            self.height = ko.observable();
            self.bmi = ko.computed(function () {
                if (self.weight() && self.height()) {
                    return (self.weight() / (Math.pow(self.height(), 2)));
                }
                return 0;
            });
        }
        ko.applyBindings(new ViewModel());
    </script>
</body>
</html>